Micron Document
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| SparkN0de-git | SparkN0de |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Commit 41a86921e196e03798d8d58d851108ce08d72849


Parents : a74b3c2
Author : Ivan <ivan@quad4.io>
Signature : Signature validation error
Date : 2026-04-13T18:28:03-05:00

feat(async_utils): introduce pending coroutines management; ensure execution of pending coroutines when setting the main event loop

Changes

1 files changed, 5 insertions(+), 1 deletions(-)


Diff

diff --git a/meshchatx/src/backend/async_utils.py b/meshchatx/src/backend/async_utils.py
index 016a293b..4625e4dc 100644
--- a/meshchatx/src/backend/async_utils.py
+++ b/meshchatx/src/backend/async_utils.py
@@ -7,6 +7,7 @@ from collections.abc import Coroutine
class AsyncUtils:
main_loop: asyncio.AbstractEventLoop | None = None
_pending_futures: list = []
+ _pending_coroutines: list = []
_futures_lock = threading.Lock()
_FUTURES_SWEEP_THRESHOLD = 64
@@ -48,6 +49,9 @@ class AsyncUtils:
@staticmethod
def set_main_loop(loop: asyncio.AbstractEventLoop):
AsyncUtils.main_loop = loop
+ for coro in AsyncUtils._pending_coroutines:
+ AsyncUtils.run_async(coro)
+ AsyncUtils._pending_coroutines.clear()
@staticmethod
def run_async(coroutine: Coroutine):
@@ -68,4 +72,4 @@ class AsyncUtils:
]
return
- print("WARNING: Main event loop not available. Could not schedule task.")
+ AsyncUtils._pending_coroutines.append(coroutine)


──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────